﻿using RentalSystem.Data.EF.Core;
using Web.Context;
using System;
using RentalSystem.Data.EF;

namespace Web.Helper
{
    public class LogsManager
    {
        protected IDataContext dataContext;

        public LogsManager()
        {
            this.dataContext = CurrentContext.Context.DataContext;
        }

        #region public

        #region Account Event
        public void UserLogin(string userGuid)
        {
            this.NewLog(userGuid, LogType.Login);
        }

        public void UserLogout(string userGuid)
        {
            this.NewLog(userGuid, LogType.Logout);
        }

        public void UserRegistered(string userGuid)
        {
            this.NewLog(userGuid, LogType.SignIn);
        }
        #endregion

        #region Customers events

        public void CustomerRentMovie(string userGuid, string movieGuid)
        {
            this.NewLog(userGuid, LogType.Rent, movieGuid);
        }

        public void CustomerReturnMovie(string userGuid, string movieGuid)
        {
            this.NewLog(userGuid, LogType.Return, movieGuid);
        }

        public void CustomerVoteMovie(string userGuid, string movieGuid)
        {
            this.NewLog(userGuid, LogType.Vote, movieGuid);
        }

        public void CustomerCommentMovie(string userGuid, string movieGuid)
        {
            this.NewLog(userGuid, LogType.Comment, movieGuid);
        }

        public void CustomerSelectLocation(string userGuid, string locationGuid)
        {
            this.NewLog(userGuid, LogType.SelectLocation, locationGuid);
        }


        #endregion

        #region Workers events

        public void WorkerCreateLocation(string userGuid, string locationGuid)
        {
            this.NewLog(userGuid, LogType.AddLocation, locationGuid);
        }
        public void WorkerDeleteLocation(string userGuid)
        {
            this.NewLog(userGuid, LogType.DeleteLocation);
        }
        public void WorkerUpdateLocation(string userGuid, string locationGuid)
        {
            this.NewLog(userGuid, LogType.EditLocation, locationGuid);
        }
        
        public void WorkerCreateMovie(string userGuid, string movieGuid)
        {
            this.NewLog(userGuid, LogType.AddMovie, movieGuid);
        }
        public void WorkerUpdateMovie(string userGuid, string movieGuid)
        {
            this.NewLog(userGuid, LogType.EditMovie, movieGuid);
        }
        public void WorkerDeleteMovie(string userGuid)
        {
            this.NewLog(userGuid, LogType.DeleteMovie);
        }

        public void WorkerAddUser(string userGuid, string newUserGuid)
        {
            this.NewLog(userGuid, LogType.AddUser, newUserGuid);
        }
        public void WorkerEditUser(string userGuid, string newUserGuid)
        {
            this.NewLog(userGuid, LogType.EditUser, newUserGuid);
        }
        public void WorkerDeleteUser(string userGuid)
        {
            this.NewLog(userGuid, LogType.DeleteUser);
        }

        public void WorkerEditMovieCategories(string userGuid)
        {
            this.NewLog(userGuid, LogType.EditMovieCategories);
        }

        public void WorkerEditMovieDiscs(string userGuid, string movieGuid)
        {
            this.NewLog(userGuid, LogType.EditMovieDiscs, movieGuid);
        }

        public void WorkerEditPageContent_Contact(string userGuid)
        {
            this.NewLog(userGuid, LogType.EditPageContent, "Kontakty");
        }
        public void WorkerEditPageContent_Discounts(string userGuid)
        {
            this.NewLog(userGuid, LogType.EditPageContent, "Promocje");
        }
        public void WorkerEditPageContent_Rules(string userGuid)
        {
            this.NewLog(userGuid, LogType.EditPageContent, "Regulamin");
        }

        public void WorkerReceiveReturnMovie(string userGuid, string movieGuid)
        {
            this.NewLog(userGuid, LogType.ReceiveReturn, movieGuid);
        }

        #endregion

        #endregion

        #region private

        private void NewLog(string userGuid, LogType eventType, string msg=null)
        {
            UserLogs log = new UserLogs
            {
                UserGuid = userGuid,
                UserLogDate = DateTime.Now,
                UserLogTypeID = (int)eventType,
                UserLogDescription = msg
            };

            this.dataContext.UserLogsDao.Add(log);
        }

        #endregion
    }
}